package com.hao.tool.extra.poi.word;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * 月报，处理查询时间
 *
 * @author: lanyh
 * @version: 1.0
 * @date: 2019/2/22 16:18
 * @description:
 */
public class MonthlyProcessTimeUtil {

    /**
     * 获取上月的上一年时间年份
     */
    public String yearFromLastYear() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        //得到前一个月
        calendar.add(Calendar.MONTH, -1);
        //得到前一年
        calendar.add(Calendar.YEAR, -1);
        String start = format.format(calendar.getTime());
        return start.substring(0, 4);
    }

    /**
     * 获取上月的年份
     */
    public String yearFromLastMonth() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        //得到前一个月
        calendar.add(Calendar.MONTH, -1);
        String start = format.format(calendar.getTime());
        return start.substring(0, 4);
    }

    /**
     * 获取上月的年月
     */
    public String lastMonth() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        String start = format.format(calendar.getTime());
        return start.substring(0, 7);
    }

    /**
     * 获取上上月的年月
     */
    public String doubleLastMonth() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -2);
        String start = format.format(calendar.getTime());
        return start.substring(0, 7);
    }

}